<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>超市账单管理系统</title>
  <link type="text/css" rel="stylesheet" href="css/style.css"/>
  <link rel="icon" href="">
</head>
<div id="header">
  <div class="title"></div>
  <div class="welcome">欢迎您：admin</div>
</div>
<div id="section-left">
  <ul class="left-menu">
    <li><a href="bill_list.html" target="mainFrame"><img src="images/btn_bill.gif"/></a></li>
    <li><a href="provider_list.html" target="mainFrame"><img src="images/btn_suppliers.gif"/></a>
    </li>
    <li><a href="user_list.html" target="mainFrame"><img src="images/btn_users.gif"/></a></li>
    <li><a href="#" onClick="javaScript:alert('这里实现退出操作！')"><img src="images/btn_exit.gif"/></a>
    </li>
  </ul>
</div>

<div id="section-right" style="overflow: hidden">
  <div class="main">
    <div class="optitle clearfix">
      <div class="title">用户管理&gt;&gt;</div>
    </div>
    <form id="form1" name="form1" method="post" action="/server/user/modify">
      <input id="flag" type="hidden" name="id" value="0">
      <div class="content">
        <table class="box"><font color="red"></font>
          <tr>
            <td class="field">用户名称：</td>
            <td><input type="text" name="name" class="text"/> <font color="red">*</font></td>
          </tr>
          <tr>
            <td class="field">用户密码：</td>

            <td><input type="password" name="pwd" class="text"/> <font color="red">*</font>
            </td>
          </tr>
          <tr>
            <td class="field">确认密码：</td>
            <td><input type="password" name="pwdConfirm" class="text"/> <font color="red">*</font>
            </td>
          </tr>

          <td class="field">用户权限：</td>

          <td><label>
            <input type="radio" name="userType" value="0" checked="checked"/>
            普通用户
          </label>
            <label>
              <input type="radio" name="userType" value="1"/>
              经理</label></td>
          </tr>
        </table>
      </div>
      <div class="buttons">
        <input type="submit" value="数据提交" class="input-button"/>
        <input type="button" onclick="window.location='user_list.html';" value="返回"
               class="input-button"/>
      </div>
    </form>
  </div>
</div>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/common.js"></script>
<script>
  $(function () {
    let id = getURLParameter("id");
    if (id !== undefined && id.length !== 0) {
      $.ajax({
        type: "post",
        contentType: "application/json;charset=UTF-8",
        url: "server/user/get",
        data: JSON.stringify({"id": id}),
        success: function (result) {
          if (!$.isEmptyObject(result)) {
            $("#flag").val(id);
            let lineNode = $("tbody");
            for (let prop in result) {
              // 找到以属性名作为css类的div，将内容替换为属性的值
              if (prop === "userType") {
                lineNode.find("[name='" + prop + "']").each(function () {
                  $(this).prop("checked", $(this).val() === result[prop] + "");
                });
              } else {
                lineNode.find("[name='" + prop + "']").val(result[prop]);
              }
            }
          } else {
            alert("id不存在");
          }
        }
      });
    }
  });
</script>
</body>
</html>